using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace Acms.AcmsControls
{
    [Serializable]
    [System.Xml.Serialization.XmlRoot("Flash")]
    public class FlashContentControlProperties : BaseContentControlProperties
    {
        private int resourceId;
        [System.Xml.Serialization.XmlAttribute]
        public int ResourceId
        {
            get { return resourceId; }
            set { resourceId = value; }
        }

        public bool HasResource()
        {
            return resourceId > 0;
        }

        private int width;
        [System.Xml.Serialization.XmlAttribute]
        public int Width
        {
            get { return width; }
            set { width = value; }
        }

        private int height;
        [System.Xml.Serialization.XmlAttribute]
        public int Height
        {
            get { return height; }
            set { height = value; }
        }

        private string minVersion;
        [System.Xml.Serialization.XmlAttribute]
        public string MinVersion
        {
            get { return minVersion; }
            set { minVersion = value; }
        }

        protected override void ReadValue(System.Xml.XmlReader reader)
        {
            if (reader.Name.ToLower() == "resourceid" && (reader.NodeType == System.Xml.XmlNodeType.Element || reader.NodeType == System.Xml.XmlNodeType.Attribute))
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    reader.Read();
                }
                try
                {
                    resourceId = reader.ReadContentAsInt();
                }
                catch
                {
                }
            }
            else if (reader.Name.ToLower() == "width" && (reader.NodeType == System.Xml.XmlNodeType.Element || reader.NodeType == System.Xml.XmlNodeType.Attribute))
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    reader.Read();
                }
                try
                {
                    width = reader.ReadContentAsInt();
                }
                catch
                {
                }
            }
            else if (reader.Name.ToLower() == "height" && (reader.NodeType == System.Xml.XmlNodeType.Element || reader.NodeType == System.Xml.XmlNodeType.Attribute))
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    reader.Read();
                }
                try
                {
                    height = reader.ReadContentAsInt();
                }
                catch
                {
                }
            }
            else if (reader.Name.ToLower() == "minversion" && (reader.NodeType == System.Xml.XmlNodeType.Element || reader.NodeType == System.Xml.XmlNodeType.Attribute))
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    reader.Read();
                }
                try
                {
                    minVersion = reader.ReadContentAsString();
                }
                catch
                {
                }
            }
        }

        protected override void  WriterPropertiesToXml(System.Xml.XmlWriter writer)
        {
            writer.WriteStartElement("content");

            writer.WriteAttributeString("resourceId", resourceId.ToString());
            writer.WriteAttributeString("width", width.ToString());
            writer.WriteAttributeString("height", height.ToString());
            writer.WriteAttributeString("minVersion", minVersion);

            writer.WriteEndElement();
        }
    }
}
